package com.upup.train_management.service.impl;

import com.upup.train_management.entity.Station;
import com.upup.train_management.repository.StationRepository;
import com.upup.train_management.service.StationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StationServiceImpl implements StationService {

    private final StationRepository stationRepository;

    @Autowired
    public StationServiceImpl(StationRepository stationRepository) {
        this.stationRepository = stationRepository;
    }

    @Override
    public List<Station> getAllStations() {
        return stationRepository.findAll();
    }

    @Override
    public Station getStationById(Long id) {
        return stationRepository.findById(id).orElse(null);
    }

    @Override
    public Station getStationByName(String stationName) {
        return stationRepository.findByStationName(stationName);
    }

    @Override
    public Station getStationByCode(String stationCode) {
        return stationRepository.findByStationCode(stationCode);
    }

    @Override
    public Station saveStation(Station station) {
        return stationRepository.save(station);
    }

    @Override
    public void deleteStation(Long id) {
        stationRepository.deleteById(id);
    }

    @Override
    public List<Station> getStationsByCity(String cityName) {
        return stationRepository.findByCityName(cityName);
    }

    @Override
    public List<Station> getStationsByProvince(String provinceName) {
        return stationRepository.findByProvinceName(provinceName);
    }
}